/**
 * csc(作者)
 * 2018-10-31(开始日期)
 * 2018-10-31(最终更改日期)
 * csc(最后更改者)
 * */
//跳转立即注册
$('#zhuce').on('click',function(){
	window.location.href = "registe.html?v_type=1"
})
//登录接口
var loginObj = {};
//用户名
var username;
var reg0 = /^[a-zA-Z0-9_-]{2,16}$/;
var bol0 = false;
$("#username").on('blur', function() {
	if($("#username").val() == '') {
		$('#falseHints').css('opacity','1');
		$('#errLanguage').text('用户名不能为空');
		bol0 = false;
	} else if(reg0.test($("#username").val()) == false) {
		$('#falseHints').css('opacity','1');
		$('#errLanguage').text("用户名格式不正确，请重新输入");
		bol0 = false;
	} else {
		$('#falseHints').css('opacity','0');
		username = $("#username").val();
		bol0 = true;
	};
});
//密码
var password;
var reg1 = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{3,16}$/
var bol1 = false;
$("#password").on('blur', function() {
	if($("#password").val() == '') {
		$('#falseHints').css('opacity','1');
		$('#errLanguage').text('密码不能为空');
		bol1 = false;
	}else {
		$('#falseHints').css('opacity','0');
		password = $("#password").val();
		bol1 = true;
	};
});

//调取登录接口

	$('#loginBtn').on('click',function(){
		var loginObj = {};
		if(bol0&&bol1){
			loginObj.username = username;
			loginObj.password = password;
			$.ajax({
				type:"post",
				url:apicom+"/login/login",
				async:true,
				data:loginObj,
				success:function(res){	
					if(res.code==200){
						var userInfo = JSON.stringify(res.data);
							loginName = res.data.loginName		
						localStorage.setItem('user_info',userInfo);
						$('#login').text(res.data.loginName);
						window.location.href = 'index.html';
					}else{
						tips(res.message)
					}
				},
				error:function(err){
					console.log(err)
				}
			});
		}else{
			tips('请检查登录信息是否完整')
		}
	})
//忘记密码
$('#remaber_pass').on('click',function(){
	window.location.href = 'find_password.html'
})
